//
//  NearbyTableViewCell.m
//  WildDonkey
//
//  Created by 孙俊 on 15/4/1.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "NearbyTableViewCell.h"
#import "UIImageView+WebCache.h"

@implementation NearbyTableViewCell

- (void)dealloc
{
	[_geodist release];
	[_type release];
	[_avatat release];
	[_name release];
	[super dealloc];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
	
	self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
	if (self) {
		
		CGRect rect = [[UIScreen mainScreen] bounds];
		CGFloat width = rect.size.width;
		CGFloat height = rect.size.height;
		
		UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, width - 20, height / 6)];
		//[bgView setBackgroundColor:[UIColor greenColor]];
		
		CGFloat bgHeight = bgView.frame.size.height;
		CGFloat bgWidth = bgView.frame.size.width;
		
		_avatat = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, (bgWidth - 20) /4, (bgWidth - 20) /4)];
		//[self.avatat setBackgroundColor:[UIColor redColor]];
		[bgView addSubview:self.avatat];
		
		CGFloat avatatWidth = self.avatat.frame.size.width;
		CGFloat avatatHeight = self.avatat.frame.size.height;
		
		_name = [[UILabel alloc] initWithFrame:CGRectMake(10 + 10 + avatatWidth, 10, bgWidth - avatatWidth - 40, bgHeight / 3)];
		//[self.name setBackgroundColor:[UIColor  redColor]];
		self.name.textAlignment = NSTextAlignmentLeft;
		[bgView addSubview:self.name];
		
		CGFloat typeWidth = self.name.frame.size.width;
		CGFloat typeHeight = self.name.frame.size.height;
		CGFloat typeX = self.name.frame.origin.x;
		CGFloat typeY = self.name.frame.origin.y + typeHeight + 5;
		
		
		_type = [[UILabel alloc] initWithFrame:CGRectMake(typeX, typeY, typeWidth, typeHeight)];
		//[self.type setBackgroundColor:[UIColor grayColor]];
		self.type.textAlignment = NSTextAlignmentLeft;
		[bgView addSubview:self.type];
		
		

		[self.contentView addSubview:bgView];
		[bgView release];
		bgView = nil;
		
	}
	return self;
}

- (void)setData:(NearbyData *)data
{
	if (_data != data) {
		[_data release];
		_data = [data retain];
		
		self.name.text = data.name;
		self.type.text = data.address;
		
		[self.avatat setImageWithURL:[NSURL URLWithString:data.avatar]];
	
	}
}


@end
